#if 0
#include <buola/cv/coctreeview.h>
#include <buola/image/format.h>
#include <buola/image/io.h>
#include <buola/gl.h>

namespace buola { namespace cvi {

using namespace gui;

COcTreeView::COcTreeView()
    :   mZoom(1.0)
    ,   mDragging(false)
    ,   mCameraPos({0,0,0})
    ,   mFlags(FLAG_NONE)
    ,   mVertexBO(0)
    ,   mIndexBO(0)
{
    SetBackColor({0.0,0.0,0.0});
    Resize(CSize_d(840,480));
    SetPaintMode(EPaintMode::OPENGL);
}

void COcTreeView::SetOcTree(COcTree<float> &&pTree)
{
    mTree=std::move(pTree);
    SetCameraPos(mat::CVec3d({-100,0,0}));
}

void COcTreeView::SetCameraPos(const mat::CVec3d &pPos)
{
    mCameraPos=pPos;

    mFlags&=~FLAG_HAVECAMERAINFO;
}

void COcTreeView::SetUpVector(const mat::CVec3d &pV)
{
    mUserUpVector=pV;

    mFlags&=~FLAG_HAVECAMERAINFO;
    mFlags|=FLAG_HAVEUPVECTOR;
}

void COcTreeView::SetLookAtPos(const mat::CVec3d &pPos)
{
    mLookAtPos=pPos;

    mFlags&=~FLAG_HAVECAMERAINFO;
    mFlags|=FLAG_HAVELOOKATPOS;
}

void COcTreeView::DrawPoints()
{
#if 0
    end_timer();
    start_timer();
    glEnableClientState(GL_VERTEX_ARRAY);

    gl::color({1.0,1.0,1.0});

    if(!(mFlags&FLAG_HAVEVBO))
        GenerateVBOs();

    glBindBuffer(GL_ARRAY_BUFFER,mVertexBO);
    glVertexPointer(3,GL_FLOAT,0,nullptr);
    glEnable(GL_PRIMITIVE_RESTART);
    
    
    glDisable(GL_BLEND);
    glDrawElements(GL_TRIANGLE_STRIP,mNumIndices,GL_UNSIGNED_INT,nullptr);

    msg_info() << mNumIndices << "\n";
    
    glDisableClientState(GL_VERTEX_ARRAY);
    glFinish();
#endif
}

void COcTreeView::GenerateVBOs()
{
    if(mFlags&FLAG_HAVEVBO)
        return;

    if(!mIndexBO)
    {
        glGenBuffers(1,&mIndexBO);
        glGenBuffers(1,&mVertexBO);
    }


    std::vector<float> lVertices(24*mTree.size());
    std::vector<GLuint> lIndices(30*mTree.size());

    int c=0;
    int v=0;
    int n=0;

    double lSize=mTree.Resolution()/7.0;
    
    for(auto i=mTree.begin();i!=mTree.end();++i)
    {
        if(i->Value()>0) continue;
        msg_info() << i->Value() << "\n";
        mat::CVec3d lPoint=i.Coords();
        mat::CVec3d lV1{lPoint.x()-lSize,lPoint.y()-lSize,lPoint.z()-lSize};
        mat::CVec3d lV2{lPoint.x()+lSize,lPoint.y()+lSize,lPoint.z()+lSize};

        lVertices[c++]=lV1.x();
        lVertices[c++]=lV1.y();
        lVertices[c++]=lV1.z();

        lVertices[c++]=lV2.x();
        lVertices[c++]=lV1.y();
        lVertices[c++]=lV1.z();

        lVertices[c++]=lV2.x();
        lVertices[c++]=lV2.y();
        lVertices[c++]=lV1.z();

        lVertices[c++]=lV1.x();
        lVertices[c++]=lV2.y();
        lVertices[c++]=lV1.z();

        lVertices[c++]=lV1.x();
        lVertices[c++]=lV1.y();
        lVertices[c++]=lV2.z();

        lVertices[c++]=lV2.x();
        lVertices[c++]=lV1.y();
        lVertices[c++]=lV2.z();

        lVertices[c++]=lV2.x();
        lVertices[c++]=lV2.y();
        lVertices[c++]=lV2.z();

        lVertices[c++]=lV1.x();
        lVertices[c++]=lV2.y();
        lVertices[c++]=lV2.z();

        lIndices[n++]=v;
        lIndices[n++]=v+1;
        lIndices[n++]=v+3;
        lIndices[n++]=v+2;
        lIndices[n++]=16777216;
        
        lIndices[n++]=v+3;
        lIndices[n++]=v+2;
        lIndices[n++]=v+7;
        lIndices[n++]=v+6;
        lIndices[n++]=16777216;

        lIndices[n++]=v+2;
        lIndices[n++]=v+1;
        lIndices[n++]=v+6;
        lIndices[n++]=v+5;
        lIndices[n++]=16777216;

        lIndices[n++]=v+1;
        lIndices[n++]=v+0;
        lIndices[n++]=v+5;
        lIndices[n++]=v+4;
        lIndices[n++]=16777216;

        lIndices[n++]=v+0;
        lIndices[n++]=v+3;
        lIndices[n++]=v+4;
        lIndices[n++]=v+7;
        lIndices[n++]=16777216;

        lIndices[n++]=v+7;
        lIndices[n++]=v+6;
        lIndices[n++]=v+4;
        lIndices[n++]=v+5;
        lIndices[n++]=16777216;

        v+=8;
    }

    glBindBuffer(GL_ARRAY_BUFFER,mVertexBO);
    glBufferData(GL_ARRAY_BUFFER,c*sizeof(float),lVertices.data(),GL_STATIC_DRAW);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,mIndexBO);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER,n*sizeof(GLuint),lIndices.data(),GL_STATIC_DRAW);
    glPrimitiveRestartIndex(16777216);
    
    mFlags|=FLAG_HAVEVBO;

    mNumVertices=v;
    mNumIndices=n;
}

void COcTreeView::GenerateCameraInfo()
{
    if(mFlags&FLAG_HAVECAMERAINFO)
        return;

    if(!(mFlags&FLAG_HAVELOOKATPOS))
    {
        mLookAtPos=mat::CVec3d({0,0,0});
    }

    mat::CVec3d lToObject=mLookAtPos-mCameraPos;
    lToObject/=norm(lToObject);

    if(mFlags&FLAG_HAVEUPVECTOR)
    {
        mUpVector=mUserUpVector-lToObject*dot(lToObject,mUserUpVector);
        mUpVector/=norm(mUpVector);
    }
    else
    {
        mUpVector=mat::CVec3d({0,0,1})-lToObject*dot(lToObject,mat::CVec3d({0,0,1}));
        mUpVector/=norm(mUpVector);
    }
    mRightVector=cross(lToObject,mUpVector);

    mFlags|=FLAG_HAVECAMERAINFO;
}

void COcTreeView::OnExpose(CExposeEvent*)
{
    if(mTree.empty()) return;

    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    glDisable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    glDepthMask(GL_TRUE);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    glFrontFace(GL_CW);

    if(!(mFlags&FLAG_HAVECAMERAINFO))
        GenerateCameraInfo();

    DrawPoints();
}

void COcTreeView::OnButtonDown(const CMouseEvent &pE)
{
    if(pE.mButton==MOUSE_LEFT)
    {
        mDragging=true;
        mDragRotation=mRotation;
        mDragPoint=pE->mPoint;
    }
    else if(pE->mButton==MOUSE_ZUP)
    {
        mZoom*=1.1;
        Refresh();
    }
    else if(pE->mButton==MOUSE_ZDOWN)
    {
        mZoom/=1.1;
        Refresh();
    }
}

void COcTreeView::OnButtonUp(const CMouseEvent &pE)
{
    if(pE->mButton==MOUSE_LEFT)
    {
        mDragging=false;
    }
}

void COcTreeView::OnMouseMove(CMouseEvent *pE)
{
    if(mDragging)
    {
        CPoint_d lDiff=pE->mPoint-mDragPoint;
        if(norm(lDiff)==0) return;
        mat::CQuat_d lRot=mat::CQuat_d(0.02*norm(lDiff),(lDiff.x*mUpVector+lDiff.y*mRightVector)/norm(lDiff));
        mRotation=lRot*mDragRotation;
        Refresh();
    }
}

/*namespace cvi*/ } /*namespace buola*/ }
#endif